
		**********************************************************
		** File: Figure_3.do									**
		** Paper: Human Trafficking Indicators: A New Dataset	**
		** Author: Richard Frank								**
		** Date: July 11, 2021									**
		** Task: Creating Figure 3								**
 		**********************************************************
 
			clear
			version 16.1
			set max_memory 32g, permanently
			set seed 1234
			set level 95 		
			
		 
 	use "HTI_v1.dta"
 
 	sort year
	by year: egen totalcountries=count(ccode)
	label var totalcountries "Total # countries in given year"

*********************
** Victim Services **
*********************


**DICHOTOMIZING **

	gen vsyesdich=.
	replace vsyesdich =1 if victimservices==1
	label var vsyesdich "victimservices= yes(dich)"

	gen vsnodich=.
	replace vsnodich =1 if victimservices==-1	
	label var vsnodich "victimservices=no (dich)"


**TOTAL IN A YEAR **

	sort year
	by year: egen vsyestot=count(vsyesdich)
	label var vsyestot "Total # victimservices=yes in a year"

	sort year
	by year: egen vsnotot=count(vsnodich)
	label var vsnotot "Total # victimservices=no in a year"


**PERCENTAGE **

	gen vsyespct=vsyestot/totalcountries
	label var vsyespct "Yes"

	gen vsnopct=vsnotot/totalcountries
	label var vsnopct "No"


	twoway (line vsyespct year, sort) ///
	 (line vsnopct year, sort), ///
	 ytitle(% of countries in sample)   legend(pos(6) cols(3))
	graph save victimservices.gph, replace

 
  *******************************************
  *** international agreement ratification **
  *******************************************
 
	  
	  ************************
	  * Palermo ratification *
	  
	  split UNP_rat, gen(pal)
	  gen ratyr=substr(pal3, strpos(pal3, "-") +1, 4)
	  drop pal*
	  destring ratyr, replace
	  sort ccode year
	  by ccode: egen palrat=max(ratyr)
	  gen palratdum=0
	  replace palratdum=1 if year>=palrat
	  drop ratyr palrat
	  label var palratdum "Palermo ratified"
	  
	  *************
	  *  ILO 105 **
	  sort ccode year
	  browse ccode country year ILO105
	  by ccode: egen ilo=max(ILO105)
	  gen iloyr=year(ilo)
	  
	  gen iloratdum=0
	  replace iloratdum=1 if year>=iloyr
	  drop ilo iloyr
	  label var iloratdum "ILO 105 ratified"
	  
	  **************************************
	  **Convention on rights of the child **
	  
	  sort ccode year
	  browse ccode country year UNCRC_rat 	  
	  split UNCRC_rat, gen(kid)
	  gen ratyr=substr(kid3, strpos(kid3, "-") +1, 4)
	  drop kid*
	  destring ratyr, replace
	  sort ccode year
	  by ccode: egen kidrat=max(ratyr)
	  gen kidratdum=0
	  replace kidratdum=1 if year>=kidrat
	  drop ratyr kidrat
	  label var kidratdum "Right of child ratified"	  
	  
	  
	  ** Convention on children in armed conflict **
	  browse ccode country year  conflict_rat	
	  split conflict_rat, gen(con)
	  gen ratyr=substr(con3, strpos(con3, "-") +1, 4)
	  drop con*
	  destring ratyr, replace
	  sort ccode year
	  by ccode: egen conrat=max(ratyr)
	  gen conratdum=0
	  replace conratdum=1 if year>=conrat
	  drop ratyr conrat
	  label var conratdum "Right of child ratified"	  
	  	  
	*** CEDAW **
	
	browse ccode country year    CEDAW_rat
	split CEDAW_rat, gen(ced)
	  gen ratyr=substr(ced3, strpos(ced3, "-") +1, 4)
	  drop ced*
	  destring ratyr, replace
	  sort ccode year
	  by ccode: egen cedrat=max(ratyr)
	  gen cedratdum=0
	  replace cedratdum=1 if year>=cedrat
	  drop ratyr cedrat
	  label var cedratdum "CEDAW  ratified"	  
	  	  	  
		  
	  keep ccode country year palratdum iloratdum kidratdum conratdum cedratdum
	  
	  
	  ** total countries in sample
	  
	  gen totcount=.
	  replace totcount=82 if year==2001
	  replace totcount=89 if year==2002
	  replace totcount=124 if year==2003
	  replace totcount=139 if year==2004
	  replace totcount=147 if year==2005
	  replace totcount=156 if year==2006 
	  replace totcount=161 if year==2007
	  replace totcount=165 if year==2008
	  replace totcount=172 if year==2009	  
	  replace totcount=173 if year==2010
	  replace totcount=179 if year==2011
	  replace totcount=182 if year==2012	  
	  replace totcount=182 if year==2013
	  replace totcount=178 if year==2014
	  replace totcount=178 if year==2015	  
	  replace totcount=177 if year==2016
	  replace totcount=179 if year==2017	  
	  
	collapse (first) totcount (sum) cedratdum palratdum iloratdum kidratdum conratdum, by(year)
	  
	  gen pal=palratdum/totc
	  gen ilo=ilo/totc
	  gen kid=kid/totc
	  gen con=con/totc
	  gen ced=ced/totc
	  
	  twoway 	///
		(line pal year) 	///
	  (line ilo year) 	///
	  (line kid year) 	///
	  (line ced year) ///
	  (line con year) 	 /// 
	  , legend (cols(5) pos(6)) xtitle("") xlabel(2001(2)2017)
	  graph save "treaties graph.gph", replace
	  
	  graph combine victimservices.gph  "treaties graph.gph", ycommon


	  
	  
	  
	   
